{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## PostGIS\n",
    "\n",
    "* PosgreSQLには地理情報に関する機能を集めたPostGIS呼ばれる拡張がある\n",
    "\n",
    "* 参考\n",
    "    * [PostGIS（地理情報システムを実現するための拡張モジュール](https://www.sraoss.co.jp/technology/postgresql/3rdparty/PostGIS.php)\n",
    "    * [PostGISのよく使う機能をまとめた](http://d.hatena.ne.jp/EulerDijkstra/20131008/1381190780)\n",
    "    * [PostGIS日本語マニュアル](https://www.finds.jp/docs/pgisman/1.5.1/ch01.html)\n",
    "    \n",
    "## Geometry データ型\n",
    "\n",
    "* データ型\n",
    "    * POINT\n",
    "        * 点（位置、ランドマーク）を表す\n",
    "    * LINESTRING\n",
    "        * 線（道路や川）を表す\n",
    "    * POLYGON\n",
    "        * 面、多角形（領域、町丁目）を表す\n",
    "    * これらの複数の要素をあらわす MULTIPOINT、MULTISTRING、MULTIPOLYGON\n",
    "        * ただし、PostgreSQL のデータ型としては共通の geometry 型を使う\n",
    "        * ある geometry 型カラムにおける内部的なデータ型は、型の属性として保持される\n",
    "* 形式\n",
    "    * WKT/WKB形式\n",
    "    * EWKT/EWKB形式\n",
    "        * 3次元対応やSRID（空間参照系の識別子）付記ができるように拡張されている\n",
    "        * SRIDの例\n",
    "            * 「4326」であればGPSで使用されるWGS84測地系に基づく緯度・経度であるという意味\n",
    "            * SRIDがばらついていると位置情報がずれるので必ず統一する\n",
    "        * 例1\n",
    "            * 0101000020E610000000000000006061400000000000004240\n",
    "                * バイナリ形式（ EWKB 形式）の 16 進数表現\n",
    "            * POINT(139 36)\n",
    "                * テキスト形式（EWKT形式）\n",
    "        * 例2 (dev1のgeomのデータ) SRID付きポイントのEWKB\n",
    "            * 010100002004120000F59ECA69CFD06040D55B035B250A4140\n",
    "            * 先頭からバイト列を読み解く\n",
    "                * 01 : エンディアン（01はリトルエンディアン）\n",
    "                * 01000020 : ジオメトリタイプ\n",
    "                    * 32ビット整数0x20000000を表す\n",
    "                        * 0x20000001がSRIDが付いていることを示すフラグ\n",
    "                * 04120000 : 整数\n",
    "                    * SRIDを示す32ビット整数\n",
    "                    * 32ビット整数0x00001204を表す\n",
    "                    * 10進数にすると4612\n",
    "                        * SRID=4612\n",
    "                * F59ECA69CFD06040 : X値\n",
    "                * D55B035B250A4140 : Y値\n",
    "* 操作関数\n",
    "    * ジオメトリー操作用の関数(ST_XXXXXX)\n",
    "        * 地理的な検索や集計を行ったり、地図として表示させるポリゴンを取得\n",
    "* 参考\n",
    "    * [WKB/EWKBを見てみる](http://qiita.com/yellow_73/items/9d69ad9512c45481952f)\n",
    "\n",
    "## Geography型\n",
    "\n",
    "* 日本国内の地図を触っているだけなら必要なさそう？\n",
    "* 厳密な距離を算出したいような場合必要かもしれない\n",
    "    * Geography型は対応している関数が少ないのでGeometryで持っている方が無難\n",
    "    * 必要な時だけGeometry型で持っているデータをGeographyに変換して操作するのがベター\n",
    "    \n",
    "## GeoJSON\n",
    "\n",
    "* JSONを用いて空間データをエンコードし非空間属性を関連付けるファイル形式\n",
    "* 属性にはポイント（住所や座標）、ライン（各種道路や境界線）、 ポリゴン（国や地域）などが含まれる\n",
    "* 多くのGIS関連ソフトウェアが対応している\n",
    "* Bing MapsやYahoo!、GoogleはAPIが対応している\n",
    "* Googleマップにはライブラリを使用するかオブジェクトをインスタンス化することによって利用できる\n",
    "    * https://github.com/JasonSanford/geojson-google-maps\n",
    "* GitHubはGeoJSONのレンダリングに対応している\n",
    "\n",
    "## 参考\n",
    "\n",
    "* [初めて地図周りの技術に触れた時に作ったまとめ資料](http://qiita.com/laqiiz/items/7d256108920ff7afbf08)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## 変換\n",
    "\n",
    "* EWKB -> EWKT -> GeoJSON\n",
    "    * GoogleMapとかで使いやすくなる？\n",
    "* ライブラリ\n",
    "    * Shapely\n",
    "        * 地理空間データ上で様々な計算を行なうためのPython用library\n",
    "        * pipで入れる\n",
    "    * fiona\n",
    "        * Shapeファイルの読み込みで使う\n",
    "\n",
    "* 参考\n",
    "    * [WKT形式をGeoJSON形式に変換する](http://qiita.com/yuichy/items/14f2cb7d4ed113eca727)\n",
    "    * [python + shapelyを使って東京都内だけに点を生成する](http://qiita.com/motokazu/items/e2668396b0723eafac5d)\n",
    "    * [国土数値情報　ダウンロードサービス](http://nlftp.mlit.go.jp/ksj/index.html)\n",
    "        * Shapeファイルをダウンロードする\n",
    "    * [シェープファイル](https://ja.wikipedia.org/wiki/%E3%82%B7%E3%82%A7%E3%83%BC%E3%83%97%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB)\n",
    "        * 他の地理情報システム(GIS)間でのデータの相互運用におけるオープン標準として用いられるファイル形式\n",
    "    * [Conversion of a GeoJSON into EWKB format?](https://gis.stackexchange.com/questions/225196/conversion-of-a-geojson-into-ewkb-format)\n",
    "        * PythonでWKT,EWKBを扱う"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## QGIS\n",
    "\n",
    "* 地理情報システムの閲覧、編集、分析機能を有するクロスプラットフォームのオープンソースソフトウェア・GISソフト\n",
    "* 参考\n",
    "    * [QGIS(Wikipedia)](https://ja.wikipedia.org/wiki/QGIS)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "# データの扱いに必要なライブラリ\n",
    "import pandas as pd\n",
    "\n",
    "# ジオメトリを扱うためのライブラリ\n",
    "from shapely import geos, wkb, wkt\n",
    "\n",
    "# 初期設定はリトルエンディアン\n",
    "geos.WKBWriter.defaults['big_endian'] = False\n",
    "\n",
    "# GeoJSONを扱うためのライブラリ\n",
    "from geojson import Point, MultiPoint\n",
    "\n",
    "# jsonを扱うためのライブラリ\n",
    "import json"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## WKTをEWKBに変換"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0101000000000000000000F03F0000000000000040\n",
      "0\n",
      "4612\n",
      "010100002004120000000000000000F03F0000000000000040\n",
      "0020000001000012043FF00000000000004000000000000000\n"
     ]
    },
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"100.0\" height=\"100.0\" viewBox=\"0.0 1.0 2.0 2.0\" preserveAspectRatio=\"xMinYMin meet\"><g transform=\"matrix(1,0,0,-1,0,4.0)\"><circle cx=\"1.0\" cy=\"2.0\" r=\"0.06\" stroke=\"#555555\" stroke-width=\"0.02\" fill=\"#66cc99\" opacity=\"0.6\" /></g></svg>"
      ],
      "text/plain": [
       "<shapely.geometry.point.Point at 0x7f9383773518>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# WKTをEWKBに変換。リトルエンディアンのEWKBで単純にポイントをセット\n",
    "p = wkt.loads('POINT Z(1 2)')\n",
    "print(p.wkb_hex) \n",
    "\n",
    "# SRIDを設定できるようにする\n",
    "geos.WKBWriter.defaults['include_srid'] = True\n",
    "\n",
    "# デフォルトのSRIDの確認\n",
    "print(geos.lgeos.GEOSGetSRID(p._geom))\n",
    "\n",
    "# SRIDに4612をセット\n",
    "geos.lgeos.GEOSSetSRID(p._geom, 4612)\n",
    "print(geos.lgeos.GEOSGetSRID(p._geom))\n",
    "\n",
    "# WEKBにSIDがセットされる\n",
    "print(p.wkb_hex)\n",
    "\n",
    "# ビッグエンディアンに変更することも可能\n",
    "geos.WKBWriter.defaults['big_endian'] = True\n",
    "print(p.wkb_hex)\n",
    "\n",
    "# リトルエンディアンに戻す\n",
    "geos.WKBWriter.defaults['big_endian'] = False\n",
    "p"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## WEKBからWKTに変換"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "POINT (134.525319 34.079265)\n"
     ]
    }
   ],
   "source": [
    "geom = '010100002004120000F59ECA69CFD06040D55B035B250A4140'\n",
    "shp = wkb.loads(geom, hex=True)\n",
    "print(shp)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## サンプルデータをcsvから読み込む"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>geom</th>\n",
       "      <th>gps_time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>658</td>\n",
       "      <td>010100002004120000F59ECA69CFD06040D55B035B250A...</td>\n",
       "      <td>2015-06-12 22:20:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>686</td>\n",
       "      <td>01010000200412000033535A7F4BD26040D97BF1457B08...</td>\n",
       "      <td>2015-06-12 22:48:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>673</td>\n",
       "      <td>01010000200412000088653387A4D16040FAB9A1293B09...</td>\n",
       "      <td>2015-06-12 22:35:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>679</td>\n",
       "      <td>010100002004120000EBAC16D8E3D1604050FC1873D708...</td>\n",
       "      <td>2015-06-12 22:41:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>649</td>\n",
       "      <td>010100002004120000F0DB10E335D06040A31F0DA7CC09...</td>\n",
       "      <td>2015-06-12 22:11:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    id                                               geom             gps_time\n",
       "0  658  010100002004120000F59ECA69CFD06040D55B035B250A...  2015-06-12 22:20:00\n",
       "1  686  01010000200412000033535A7F4BD26040D97BF1457B08...  2015-06-12 22:48:00\n",
       "2  673  01010000200412000088653387A4D16040FAB9A1293B09...  2015-06-12 22:35:00\n",
       "3  679  010100002004120000EBAC16D8E3D1604050FC1873D708...  2015-06-12 22:41:00\n",
       "4  649  010100002004120000F0DB10E335D06040A31F0DA7CC09...  2015-06-12 22:11:00"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv(\"csv/geosample.csv\")\n",
    "df.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## WKTに変換した情報の列を追加"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'POINT (134.525319 34.079265)'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wkb.loads('010100002004120000F59ECA69CFD06040D55B035B250A4140', hex=True)\n",
    "str(wkb.loads(df['geom'][0], hex=True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>geom</th>\n",
       "      <th>gps_time</th>\n",
       "      <th>wkt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>658</td>\n",
       "      <td>010100002004120000F59ECA69CFD06040D55B035B250A...</td>\n",
       "      <td>2015-06-12 22:20:00</td>\n",
       "      <td>POINT (134.525319 34.079265)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>686</td>\n",
       "      <td>01010000200412000033535A7F4BD26040D97BF1457B08...</td>\n",
       "      <td>2015-06-12 22:48:00</td>\n",
       "      <td>POINT (134.571716 34.066262)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>673</td>\n",
       "      <td>01010000200412000088653387A4D16040FAB9A1293B09...</td>\n",
       "      <td>2015-06-12 22:35:00</td>\n",
       "      <td>POINT (134.551334 34.072118)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>679</td>\n",
       "      <td>010100002004120000EBAC16D8E3D1604050FC1873D708...</td>\n",
       "      <td>2015-06-12 22:41:00</td>\n",
       "      <td>POINT (134.559063 34.069075)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>649</td>\n",
       "      <td>010100002004120000F0DB10E335D06040A31F0DA7CC09...</td>\n",
       "      <td>2015-06-12 22:11:00</td>\n",
       "      <td>POINT (134.506578 34.076558)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    id                                               geom  \\\n",
       "0  658  010100002004120000F59ECA69CFD06040D55B035B250A...   \n",
       "1  686  01010000200412000033535A7F4BD26040D97BF1457B08...   \n",
       "2  673  01010000200412000088653387A4D16040FAB9A1293B09...   \n",
       "3  679  010100002004120000EBAC16D8E3D1604050FC1873D708...   \n",
       "4  649  010100002004120000F0DB10E335D06040A31F0DA7CC09...   \n",
       "\n",
       "              gps_time                           wkt  \n",
       "0  2015-06-12 22:20:00  POINT (134.525319 34.079265)  \n",
       "1  2015-06-12 22:48:00  POINT (134.571716 34.066262)  \n",
       "2  2015-06-12 22:35:00  POINT (134.551334 34.072118)  \n",
       "3  2015-06-12 22:41:00  POINT (134.559063 34.069075)  \n",
       "4  2015-06-12 22:11:00  POINT (134.506578 34.076558)  "
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv(\"csv/geosample.csv\")\n",
    "\n",
    "wkt_list = []\n",
    "for i in df['geom']:\n",
    "    wkt_list.append(str(wkb.loads(i, hex=True)))\n",
    "\n",
    "df_wkt = pd.DataFrame(wkt_list, columns=['wkt'])\n",
    "df = pd.merge(df, df_wkt, how='inner', left_index=True, right_index=True).head(5)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "source": [
    "## geoJSONに変換"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "### サンプル"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{\"coordinates\": [[-155.52, 19.61], [-156.22, 20.74], [-157.97, 21.46]], \"type\": \"MultiPoint\"}"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MultiPoint([(-155.52, 19.61), (-156.22, 20.74), (-157.97, 21.46)]) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(-155.52, 19.61), (-156.22, 20.74), (-157.97, 21.46)]"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[(-155.52, 19.61), (-156.22, 20.74), (-157.97, 21.46)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "### wktの値をMultiPointで読み込めるタプルの形式に変換"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'POINT (134.525319 34.079265)'"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wkt_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(134.525319, 34.079265)"
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tuple(list(map(float, wkt_list[0].replace('POINT (','').replace(')','').split(\" \"))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(134.525319, 34.079265),\n",
       " (134.571716, 34.066262),\n",
       " (134.551334, 34.072118),\n",
       " (134.559063, 34.069075),\n",
       " (134.506578, 34.076558),\n",
       " (134.536451, 34.077989),\n",
       " (134.534515, 34.078336),\n",
       " (134.539264, 34.077632),\n",
       " (134.509309, 34.076836),\n",
       " (134.528308, 34.078943),\n",
       " (134.549405, 34.072755),\n",
       " (134.537325, 34.077869),\n",
       " (134.530481, 34.078844),\n",
       " (134.547608, 34.074001),\n",
       " (134.55637, 34.071566),\n",
       " (134.562238, 34.068694),\n",
       " (134.56414, 34.068111),\n",
       " (134.532339, 34.078585),\n",
       " (134.558045, 34.071388),\n",
       " (134.565874, 34.067395),\n",
       " (134.526516, 34.079298),\n",
       " (134.518171, 34.07827),\n",
       " (134.560153, 34.068926),\n",
       " (134.516142, 34.077915),\n",
       " (134.520622, 34.078738),\n",
       " (134.573602, 34.065823),\n",
       " (134.511125, 34.077087),\n",
       " (134.523144, 34.079138),\n",
       " (134.574081, 34.065051),\n",
       " (134.570538, 34.06648),\n",
       " (134.544805, 34.076734),\n",
       " (134.552256, 34.07181),\n",
       " (134.558711, 34.070281),\n",
       " (134.541633, 34.077275)]"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wkt_list_for_geojson = []\n",
    "for i in wkt_list:\n",
    "    wkt_list_for_geojson.append(tuple(list(map(float, i.replace('POINT (','').replace(')','').split(\" \")))))\n",
    "wkt_list_for_geojson"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "### geoJSONに変換"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{\"coordinates\": [[134.525319, 34.079265], [134.571716, 34.066262], [134.551334, 34.072118], [134.559063, 34.069075], [134.506578, 34.076558], [134.536451, 34.077989], [134.534515, 34.078336], [134.539264, 34.077632], [134.509309, 34.076836], [134.528308, 34.078943], [134.549405, 34.072755], [134.537325, 34.077869], [134.530481, 34.078844], [134.547608, 34.074001], [134.55637, 34.071566], [134.562238, 34.068694], [134.56414, 34.068111], [134.532339, 34.078585], [134.558045, 34.071388], [134.565874, 34.067395], [134.526516, 34.079298], [134.518171, 34.07827], [134.560153, 34.068926], [134.516142, 34.077915], [134.520622, 34.078738], [134.573602, 34.065823], [134.511125, 34.077087], [134.523144, 34.079138], [134.574081, 34.065051], [134.570538, 34.06648], [134.544805, 34.076734], [134.552256, 34.07181], [134.558711, 34.070281], [134.541633, 34.077275]], \"type\": \"MultiPoint\"}"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MultiPoint(wkt_list_for_geojson) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "### ファイルに出力"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "f = open(\"json/geosample.geojson\", \"w\")\n",
    "#json.dump(MultiPoint(wkt_list_for_geojson), f, ensure_ascii=False, indent=4, sort_keys=True, separators=(',', ': '))\n",
    "json.dump(MultiPoint(wkt_list_for_geojson), f, ensure_ascii=False, indent=4)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
